package com.qd.push.config;

import com.cdqidi.exception.ApiException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author sjk
 */
@Data
@Component
@ConfigurationProperties("push-config")
public class PushConfig {
    private Map<Integer, Integer> delayMap;
    private final Lock lock = new ReentrantLock();

    public Integer getDelayTime(Integer key) {
        if (null == delayMap || delayMap.isEmpty()) {
            throw new ApiException("请配置push-config");
        }
        try {
            lock.lock();
            return delayMap.get(key);
        } finally {
            lock.unlock();
        }
    }
}
